package wei.qiang.ye.spvalidationdemo.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.aop.framework.AopContext;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import wei.qiang.ye.spvalidationdemo.dto.UserDTO;

import javax.validation.Valid;
import javax.validation.constraints.Min;

@Service
@Validated
public class UserServiceImpl {
    private Logger logger = LoggerFactory.getLogger(getClass());

    public void get(@Min(value = 1L, message = "编号必须大于 0") Integer id) {
        logger.info("[get][id: {}]", id);
    }

    public void add(@Valid UserDTO addDTO) {
        logger.info("[add][addDTO: {}]", addDTO);
    }

    public void add01(UserDTO addDTO) {
        this.add(addDTO);
    }

    public void add02(UserDTO addDTO) {
        self().add(addDTO);
    }

    /**
     * 获取到当前的代理对象
     * @return
     */
    private UserServiceImpl self() {
        return (UserServiceImpl) AopContext.currentProxy();
    }
}
